/*
2010/11/11 22:28:41
*/


namespace LanSunERP
{
    using System;
    using System.ServiceModel;
    using System.Windows.Forms;
    using System.Diagnostics;
    using System.Collections.Generic;
    using System.Runtime.Serialization;
    using System.Collections;
    using System.Data;
    using System.Data.SqlClient;

    public class TableList : QueryCommand
    {
        public TableList() : base() { }
        public TableList(SqlCommand cmdSQL, DataTable dtRequest, string RequestJob)
            : base(cmdSQL, dtRequest, RequestJob) { }
        public SqlCommand BuildCommand()
        {

            switch (RequestJob.Substring(6,4))
            {
                case "0000": 
                /*
                     case "TableList":
                        TableList m_TableList = new TableList(cmdSQL, dtRequest, RequestJob);
                        cmdSQL = m_TableList.BuildCommand();
                        break;
                */
                    break;
                case "1000": 
                    break;
                 case "2001":
                 case "4000":
                    cmdSQL.Parameters.Add(new SqlParameter("@InstanceID", dwRequest["InstanceID"].ToString()));
                    break; 
                case "1023":  //IX_TableList
                  cmdSQL.Parameters.Add(new SqlParameter("@SysID", dwRequest["SysID"].ToString()));  
                  cmdSQL.Parameters.Add(new SqlParameter("@TableName", dwRequest["TableName"].ToString()));  
                    break;
                case "1620":  //TX_TableList
                  cmdSQL.Parameters.Add(new SqlParameter("@SysID", dwRequest["SysID"].ToString()));  
                  cmdSQL.Parameters.Add(new SqlParameter("@TableName", dwRequest["TableName"].ToString()));  
                    break;
               case "2000": 
               case "3001":
               case "3000":
                    cmdSQL.Parameters.Add(new SqlParameter("@SysID", dwRequest["SysID"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@TableID", dwRequest["TableID"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@TableName", dwRequest["TableName"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@ShortName", dwRequest["ShortName"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@SubStatus", dwRequest["SubStatus"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@KeyCondition", dwRequest["KeyCondition"].ToString()));
                    cmdSQL.Parameters.Add(new SqlParameter("@Status", dwRequest["Status"].ToString()));
                    break;
            }
            return cmdSQL;

        }
        public override SqlCommand BuildInstanceKey(SqlCommand cmdSQL, DataRow dwTemp)
        {
            
                string InstanceKey = dwTemp["InstanceKey"].ToString().Trim();
                    string SysID=dwTemp["SysID"].ToString().Trim();
                    string TableName=dwTemp["TableName"].ToString().Trim();
           
            {
                if (SysID!=""&&TableName!="")
                {
                    InstanceKey =SysID+"."+TableName;
                    dwTemp["InstanceKey"] = InstanceKey;
                    dwTemp.AcceptChanges();
                }
            }
            cmdSQL.Parameters.Add(new SqlParameter("@InstanceKey", dwRequest["InstanceKey"].ToString()));
            return base.BuildInstanceKey(cmdSQL, dwTemp);
        }
}
 public class TableListQueryCond : QueryCommand
    {
        public TableListQueryCond() : base() { }
        public TableListQueryCond(SqlCommand cmdSQL, DataTable dtRequest, string RequestJob)
         : base(cmdSQL, dtRequest,RequestJob) {  }

        public SqlCommand BuildCommand()
        {
            switch (RequestJob.Substring(6,4))
            {
                case "0000": break;
                case "1000": break;
                case "1001": break;
                case "1002": break;
                case "2000": 
                case "3000":
                    cmdSQL.Parameters.Add(new SqlParameter("@SysID", dwRequest["SysID"].ToString()));
cmdSQL.Parameters.Add(new SqlParameter("@TableID", dwRequest["TableID"].ToString()));
cmdSQL.Parameters.Add(new SqlParameter("@TableName", dwRequest["TableName"].ToString()));
cmdSQL.Parameters.Add(new SqlParameter("@ShortName", dwRequest["ShortName"].ToString()));
cmdSQL.Parameters.Add(new SqlParameter("@SubStatus", dwRequest["SubStatus"].ToString()));
cmdSQL.Parameters.Add(new SqlParameter("@KeyCondition", dwRequest["KeyCondition"].ToString()));
cmdSQL.Parameters.Add(new SqlParameter("@Status", dwRequest["Status"].ToString()));
cmdSQL.Parameters.Add(new SqlParameter("@FrstUser", dwRequest["FrstUser"].ToString()));
cmdSQL.Parameters.Add(new SqlParameter("@FrstDate", dwRequest["FrstDate"].ToString()));
cmdSQL.Parameters.Add(new SqlParameter("@LastUser", dwRequest["LastUser"].ToString()));
cmdSQL.Parameters.Add(new SqlParameter("@LastDate", dwRequest["LastDate"].ToString()));
                
                    break;
                case "4000":
                    cmdSQL.Parameters.Add(new SqlParameter("@InstanceID", dwRequest["InstanceID"].ToString())); 
                    break;
            }
             return cmdSQL;

        }      

    }
 }

